<?php

use App\Models\Advertisement;

return [
    'title' => '广告管理',
    'heading' => '广告管理',
    'single' => '广告',
    'model' => Advertisement::class,

    'query_filter' => function ($query) {
        if (!Input::get('sortOptions')) {
            $query->orderBy('sort', 'ASC');
        }
    },

    'columns' => [
        'id' => [
            'title' => 'ID',
        ],
        'position' => [
            'title' => '位置',
        ],
        'title' => [
            'title' => '标题',
            'output' => function ($value, $model) {
                return $model->link ? "<a href='{$model->link}' target='_blank'>{$value}</a>" : $value;
            },
        ],
        'target' => [
            'title' => '打开方式',
            'output' => function ($value) {
                return $value == '_blank' ? '新窗口打开' : '本站打开';
            },
        ],
        'image_url' => [
            'title' => '图片',
            'sortable' => false,
            'output' => function ($value, $model) {
                return $value ? "<img src='{$value}' width='200' height='100'>" : 'N/A';
            },
        ],
        'description' => [
            'title' => '描述',
            'sortable' => false,
            'output' => function ($value, $model) {
                return $value ? "<p style='width:250px'>$value</p>" : 'N/A';
            },
        ],
        'sort' => [
            'title' => '排序',
            'sortable' => false,
        ],
        'start_date' => [
            'title' => '开始时间',
        ],
        'end_date' => [
            'title' => '结束时间'
        ],
        'created_at' => [
            'title' => '创建时间'
        ],
        'status' => [
            'title' => '状态',
            'output' => function ($value) {
                return $value == 'yes' ? '启用' : '禁用';
            },
        ],
        'operation' => [
            'title' => '管理',
            'output' => function ($value, $model) {
                return $value;
            },
            'sortable' => false,
        ]
    ],
    'edit_fields' => [
        'position' => [
            'title' => '位置',
            'type' => 'enum',
            'options' => [
                'activity-top' => '首页上边广告(图片比例4:1)',
                'all-top'     => '所有上边广告（图片比例4:1）',//除了首页和招聘版块不显示外，其余都显示的
                'post-tail'   => '帖子尾部广告（图片比例2:1）' //在所有帖子尾部增加广告（这里可能需要根据分类来分）
            ],
        ],
        'title' => [
            'title' => '标题',
        ],
        'target' => [
            'title' => '打开方式',
            'type' => 'enum',
            'options' => [
                '_blank' => '新窗口打开',
                '_self' => '本站打开',
            ],
            'value' => '_blank',
        ],
        'link' => [
            'title' => '链接地址',
        ],
        'image_url' => [
            'title' => '封面',
            'type' => 'image',
            'location' => public_path() . '/uploads/advertisement/',
            'naming' => 'random',
            'length' => 20,
            'size_limit' => 2,
            'display_raw_value' => false,
        ],
        'description' => [
            'title' => '描述',
            'type' => 'textarea',
        ],
        'sort' => [
            'title' => '排序（按小到大排序）',
            'type' => 'number',
            'value' => 0,
        ],
        'start_date' => [
            'title' => '开始时间',
            'type' => 'datetime'
        ],
        'end_date' => [
            'title' => '结束时间',
            'type' => 'datetime'
        ],
        'status' => [
            'title' => '状态',
            'type' => 'enum',
            'options' => [
                'no' => '禁用',
                'yes' => '启用',
            ],
        ],
    ],
    'filters' => [
        'id' => [
            'title' => 'ID',
        ],
        'position' => [
            'title' => '位置',
        ],
        'title' => [
            'title' => '标题',
        ],
        'sort' => [
            'title' => '排序（按小到大排序）',
            'type' => 'number',
        ],
    ],
];
